//
//  ZYTabBar.m
//  VeiBo
//
//  Created by apple on 16/12/2.
//  Copyright © 2016年 apple. All rights reserved.
//

//@interface foo
//-(int)add:int val;
//@end
//SEL class_func ; //定义一个类方法指针
//class_func = @selector(add:int);

#import "ZYTabBar.h"

@implementation ZYTabBar

- (void)layoutSubviews{
    
    UIButton* button = [UIButton ZY_setImageName:@"tabbar_compose_icon_add" backgroundImgName:@"tabbar_compose_button" target:self action:@selector(buttonClick:)];
    [self addSubview:button];
    [super layoutSubviews];
    button.center = CGPointMake(ZYMainScreenWidth * 0.5, self.frame.size.height * 0.5);
    float btnw = ZYMainScreenWidth * 0.2;
    [self.subviews enumerateObjectsUsingBlock:^(UIButton* obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
            if (idx == 3||idx == 4) {
                idx++;
            }
            if ([obj isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
                
                obj.frame = CGRectMake(btnw * (idx-1), 0, btnw, self.frame.size.height);
            }
        }];


//    UIButton* value;
//    NSInteger idx = 0;
//    float w = self.frame.size.width * 0.2;
//    for (value in self.subviews) {
//   
//        if ([value isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
//            
//            value.frame = CGRectMake(w * idx, 0, w, self.frame.size.height);
//
//            idx= idx + 1;
//            if (idx==2) {
//                
//                idx++;
//            }
//        }
//    }
//    
    
}

- (void)buttonClick:sender{
    
    self.buttonBlock();
    
//    if ([_delegateNew respondsToSelector:@selector(composeButtonClickOfTabBar)]) {
//        
//        [_delegateNew composeButtonClickOfTabBar];
//    }
}

// 懒加载按钮


//- (UIButton*)button{
//    
//    _button = [[UIButton alloc] init];
//    
//    _button addTarget:<#(nullable id)#> action:(nonnull SEL) forControlEvents:<#(UIControlEvents)#>
//    
//    [_button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState: UIControlStateNormal];
//    [_button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState: UIControlStateHighlighted];
//    [_button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
//    [_button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
//    [_button sizeToFit];
//    return _button;
//    
//}

@end
